package com.jbit.dm_160.controller;

import com.jbit.dm_160.model.dto.FloorTypeDTO;
import com.jbit.dm_160.model.dto.ItemDTO;
import com.jbit.dm_160.model.dto.ItemTypeDTO;
import com.jbit.dm_160.model.dto.SchedulerSeatPriceDTO;
import com.jbit.dm_160.model.entity.*;
import com.jbit.dm_160.service.*;
import com.jbit.dm_160.utils.ResponseEntity;
import com.jbit.dm_160.utils.ResponseUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/item/api")
public class ItemHomeController {
    @Resource
    private ItemTypeService itemTypeService;
    @Resource
    private ItemService itemService;

    @Resource
    private SchedulerService schedulerService;

    @Resource
    private SchedulerSeatPriceService schedulerSeatPriceService;
    @Resource
    private ItemCommentService itemCommentService;
    @PostMapping("/p/index/queryAllType")
    public ResponseEntity<List<ItemTypeDTO>> queryAllType(){
        return ResponseUtils.sendSuccess("0000",itemTypeService.list());
    }
    @PostMapping("/p/index/queryTransverse")
    public ResponseEntity<List<ItemTypeDTO>> queryTransverse(){
        return ResponseUtils.sendSuccess("0000",itemTypeService.getFirst());
    }
    @PostMapping("/p/index/queryBanner")
    public ResponseEntity<List<ItemDTO>> queryBanner(){
        return ResponseUtils.sendSuccess("0000",itemService.getHotItems());
    }
    @PostMapping("/p/index/queryTodayRecommend")
    public ResponseEntity<List<ItemDTO>> queryTodayRecommend(){
        return ResponseUtils.sendSuccess("0000",itemService.getItemsByState(3));
    }
    @PostMapping("/p/index/queryToSaleItem")
    public ResponseEntity<List<ItemDTO>> queryToSaleItem(){
        return ResponseUtils.sendSuccess("0000",itemService.getItemsByState(2));
    }
    @PostMapping("/p/index/queryFloorItems")
    public ResponseEntity<List<FloorTypeDTO>> queryFloorItems(){
        return ResponseUtils.sendSuccess("0000",itemTypeService.getFloor());
    }
    @PostMapping("/p/type/queryItemType")
    public ResponseEntity<List<ItemTypeDTO>> queryItemType(@RequestBody ItemType itemType){
        return ResponseUtils.sendSuccess(itemTypeService.getTypesByParent(itemType.getParent()));
    }
    @PostMapping("/p/queryItemLike")
    public ResponseEntity<List<ItemDTO>> queryItemList(@RequestBody Map<String,Integer> map){
        return ResponseUtils.sendSuccess(itemService.getItemByType1Id(map.get("itemTypeId")));
    }

    @PostMapping("/p/queryItemDetail")
    public ResponseEntity<ItemDTO> queryItemDetail(@RequestBody Item item){
        ItemDTO itemDTO = itemService.getItemDetailById(item.getId());
        return ResponseUtils.sendSuccess(itemDTO);
    }
    @PostMapping("/p/queryItemScheduler")
    public ResponseEntity<List<Scheduler>> queryItemScheduler(@RequestBody Scheduler scheduler){
        List<Scheduler> schedulerList = schedulerService.getSchdulerByItemId(scheduler.getItemId());
        return ResponseUtils.sendSuccess(schedulerList);
    }
    @PostMapping("/p/queryItemPrice")
    public ResponseEntity<List<SchedulerSeatPriceDTO>> queryItemPrice(@RequestBody SchedulerSeatPrice schedulerSeatPrice){
        List<SchedulerSeatPriceDTO> schedulerSeatPriceDTOS = schedulerSeatPriceService.getSeatPriceBySchedulerId(schedulerSeatPrice.getScheduleId());
        return ResponseUtils.sendSuccess(schedulerSeatPriceDTOS);
    }
    @PostMapping("/p/queryItemComment")
    public ResponseEntity<List<ItemComment>> queryItemComment(@RequestBody Item item){
        return ResponseUtils.sendSuccess(itemCommentService.getItemCommentByItemId(item.getId()));
    }
    @PostMapping("/v/commitItemComment")
    public ResponseEntity commitItemComment(ItemComment comment){
        Integer count = itemCommentService.addItemComment(comment);
        return ResponseUtils.sendSuccess(null);
    }

}
